<template>
  <div class='center'>
    <BaseInfo />
    <Tabs @sendTableName="getNewTable" />
    <p class="add-tab">
      <span :class="{'is-active':type==1}" @click="type=1;getList()">与我相关的</span>
      <span :class="{'is-active':type==0}" @click="type=0;getList()">我提交的</span>
    </p>

    <List :listData="listData" :modelData="modelData" />
    <Add v-if="$store.state.dia.center.show" :tablename="tablename" :modelData="modelData" @reflash="getList" />
  </div>
</template>
<script>
import BaseInfo from './model/baseinfo'
import List from './model/list'
import Add from './model/common/add'
import Tabs from './model/tabs'
export default {
  components: {BaseInfo,List,Add,Tabs},
  name: "",
  data() {
    return {
      listData:[],
      modelData:[],
      tablename:"outcomes_academic",
      number:"",
      type:1,
    };
  },
  methods: {
    /**
     * 获取新的table
     */
    getNewTable(tablename=this.tablename){
      this.tablename=tablename
      this.getTableHead(tablename)
      this.getList(tablename)
    },
    
    getTableHead(tablename=this.tablename){
      let blurArray=[
        {key:'outcomes_academic',values:['title']},
        {key:'tr_thesis',values:['title']}
      ];
      let searchArray=[
        {key:"outcomes_academic",values:['author','author_2','author_other','author_comm']},
        {key:"outcomes_monograph",values:['editor','subeditor','editor_other']},
        {key:"outcomes_patent",values:['author','author_2','author_other']},
        {key:"tr_thesis",values:['author']},
        {key:"tr_project",values:['principal']},
        {key:"curriculum_change",values:['teacher']},
        {key:"top_teacher",values:['name']},
        {key:"guidance_competition",values:['teacher']},
        {key:"other_project",values:['chief']},
      ];//可以搜索的

      _g.apiPost("teacher/tableall",{tablename}).then(res=>{
        let results=[]
        res.data.forEach(ele => {
          results.push({
            prop:ele[0],
            name:ele[1],
            width:"200",
            blur:blurArray.findIndex(val=>val.key===tablename&&val.values.includes(ele[0]))>-1?true:"",
            canSearch:searchArray.findIndex(val=>val.key===tablename&&val.values.includes(ele[0]))>-1?true:false,
          })
        });
        this.$set(this,"modelData",[{type:"index",name:"序号"},].concat(results))
      })
    },

    getList(tablename=this.tablename){
      _g.apiPost("teacher/tableslistall",{tablename,number:this.number,type:this.type}).then(res=>{
        this.$set(this,"listData",res.data)
      })
    }
  },
  created() {
    this.number=_g.getRouterParams(this).number
    this.getNewTable()
  }
};
</script>
<style scoped>
.center {
}
.add-tab{
  margin-top: 20px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  box-sizing: border-box;
  border-bottom: 1px solid red;
}
.add-tab span{
  display: inline-block;
  height: 40px;line-height: 40px;
  padding: 0 10px;
}
span.is-active{
  color: #fff;
  background-color: red;
}
</style>